#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include "archtypemodel.h"
#include "entitymodel.h"
#include "editarchdialog.h"
#include "optionsdialog.h"
#include "addentdialog.h"
#include "glviewport.h"
#include "imagemanager.h"
#include "imagemodel.h"
#include "archtypestab.h"
#include "entitiestab.h"
#include "imagestab.h"
#include "scriptmodel.h"
#include "scriptstab.h"
#include "soundmodel.h"
#include "soundstab.h"
#include "scripteditorwidget.h"
#include "editarchwidget.h"
#include <QTextStream>
#include <QDomDocument>

using namespace std;

class MainWindow : public QMainWindow
{
    Q_OBJECT
    QTableView* m_archview;
    ArchtypeModel *m_archmodel;
    QTableView* m_entview;
    EntityModel *m_entmodel;
    QTableView *m_imgview;
    ImageModel *m_imgmodel;
    QTableView *m_scriptsview;
    ScriptModel *m_scriptmodel;
    QTableView *m_soundsview;
    SoundModel *m_soundmodel;
    GLViewport *m_viewport;
    ImageManager *m_imagemanager;
    ScriptEditorWidget *m_scripteditorwidget;
    EditArchWidget *m_edarch;
    QTabWidget *m_tabWidget;

public:
    MainWindow(QWidget *parent = 0);
    void keyPressEvent(QKeyEvent *event);
    bool loadXML(const QString &fileName);
    void setCurrentFile(const QString &filename);
    ~MainWindow();

public slots:
    void OpenEditArch(const QModelIndex & index );
    void OpenImage(const QModelIndex &index);
    void OpenScript(const QModelIndex &index);
    void OpenAddEnt();
    void AddArchtype();
    void CopyArchtype();
    void EraseArchtype();
    void UpdateView();
    void LoadImageK();
    void LoadScript();
    void LoadSound();
    void DeleteEntity();
    void DeleteImage();
    void DeleteScript();
    void DeleteSound();
    void OpenOptions();
    void UpdateImages();
    void SelectArchtype(AED_Archtype *arch);
    void DeselectArchtype();

private slots:
    bool load();
    bool save();
    bool saveAs();
    void about();
    void shortcuts();
    void newFile();
    void run();

private:
    void createActions();
    void createMenus();
    void createToolBars();

    bool saveFile(const QString &filename);
    bool saveXML(const QString &fileName);

    void Clean();

    QString curFile;

    QMenu *fileMenu;
    QMenu *editMenu;
    QMenu *toolsMenu;
    QMenu *helpMenu;

    QToolBar *archtypeTb;
    QToolBar *entityTb;
    QToolBar *fileTb;

    QAction *addarchAction;
    QAction *copyarchAction;
    QAction *erasearchAction;

    QAction *addentAction;
    QAction *eraseentAction;

    QAction *newFileAction;
    QAction *openAction;
    QAction *saveAction;
    QAction *saveAsAction;
    QAction *quitAction;

    QAction *runAction;

    QAction *loadImageAction;
    QAction *loadScriptAction;
    QAction *loadSoundAction;

    QAction *optionsAction;

    QAction *shortcutsAction;
    QAction *aboutAction;

    QComboBox *viewBox;
};

#endif // MAINWINDOW_H
